#ifndef TD_ANIMATION_H
#define TD_ANIMATION_H


/************************************************************************/
/* STL                                                                  */
/************************************************************************/
#include <vector> 
#include <new>


/************************************************************************/
/* PROJECT                                                              */
/************************************************************************/
#include "Core/BaseEntity.h"
#include "Core/Coord2D.h"
#include "Resources/Tiles/Tile.h"

using namespace std;
using namespace TD_Core;
using namespace TD_Resources;


namespace TD_Game {
	

	/** Animation class. Abstracts a tile sequence, simulating an animation;*/

	class Animation : public BaseEntity {

		/************************************************************************/
		/* Default values                                                       */
		/************************************************************************/
		static const unsigned int defaultAnimationInterval;
		static const string noAnimation;
	public:

		/************************************************************************/
		/* ctors and dtors                                                      */
		/************************************************************************/
		//Default constructor
		Animation();
		
		//Copy constructor
		Animation(const Animation &rhs);
		
		//Assignment constructor
		Animation & operator=(const Animation &rhs);

		//Initialization constructor
		Animation(const string &animationName, int animationInterval, bool loopAnimation = true, const Coord2D & position = Coord2D(0,0));

		~Animation();
		
		/************************************************************************/
		/* Access functions                                                     */
		/************************************************************************/
		
		inline void addAnimationTile(Tile *animTile) {
			m_tileVector.push_back(animTile);
		}
		
		const string & getName() const {
			return(m_name);
		}
		
		const vector<Tile *> & getTileVector() const {
			return(m_tileVector);
		}

		Tile * getCurrentTile() const {
			return(m_pCurrTile);
		}

		bool isLoopedAnimation() const {
			return(m_loopAnimation);
		}

		bool isFinished() const {
			return(m_animationComplete);
		}

		inline int getTotalAnimationTime() const {
			return(m_animationInterval * m_tileVector.size());
		}
		
		
		const unsigned int getAnimationInterval() const {
			return(m_animationInterval);
		}

		/************************************************************************/
		/* Functionalities                                                      */
		/************************************************************************/
		void resetAnimation();

		/************************************************************************/
		/* Rendering                                                            */
		/************************************************************************/
		void render(SDL_Surface *const g_destSurface, unsigned int deltaTime);


	private:

		/************************************************************************/
		/* Internal members                                                     */
		/************************************************************************/
		/** Animation name */
		string m_name;

		/** Current animation index*/
		unsigned int m_currAnimIndex;

		/** Timing variables.*/
		int m_animationTicks;
		int m_animationInterval;

		/** If the animation should be looped.*/
		bool m_loopAnimation;

		/** If is the first render loop.*/
		bool m_firstRenderLoop;

		/** If the animation have finished. 
		/** Only valid if the animation is not looped.*/
		bool m_animationComplete;

		/** Current animation tile.*/
		Tile *m_pCurrTile;

		/** The vector containing the tiles ordered for the animation process*/
		vector<Tile *> m_tileVector;

		/************************************************************************/
		/* Private functions                                                    */
		/************************************************************************/
		void update(unsigned int deltaTime);

	};
}

#endif